package com.qxkj.generate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.FileOutConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class MpGenerator {
    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();

        //1全局配置
        GlobalConfig gc = new GlobalConfig();
        String propertyTath = System.getProperty("user.dir");
        gc.setOutputDir("D:\\ideaSpace\\1805a\\qxkjcs_parent\\qxkjcs_client\\src\\main\\java");
        gc.setAuthor("wyh");
        gc.setOpen(false);
        gc.setFileOverride(false);
        gc.setServiceName("%sService");
        gc.setIdType(IdType.AUTO);
        gc.setDateType(DateType.ONLY_DATE);
        gc.setSwagger2(true);
        mpg.setGlobalConfig(gc);

        //2.设置数据源
        DataSourceConfig desc = new DataSourceConfig();
        desc.setDriverName("com.mysql.jdbc.Driver");
        desc.setPassword("root");
        desc.setUsername("root");
        desc.setUrl("jdbc:mysql://127.0.0.1:3306/1805aa?characterEncoding=UTF8");
        desc.setDbType(DbType.MYSQL);
        mpg.setDataSource(desc);
        //3.包的配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.qxkj");
        pc.setEntity("pojo");
        pc.setMapper("mapper");
        pc.setService("service");
        pc.setController("controller");
        mpg.setPackageInfo(pc);
        //4。配置策略
        StrategyConfig strategy = new StrategyConfig();
        strategy.setInclude("tb_cece");
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);

        //逻辑删除
        //strategy.setLogicDeleteFieldName("属性名")


        //自动填充

        /*TableFill 创建时间的字段 = new TableFill("创建时间的字段", FieldFill.INSERT);
        TableFill 修改时间的字段 = new TableFill("修改时间的字段", FieldFill.INSERT_UPDATE);



        ArrayList<TableFill> tablefiles = new ArrayList<>();
        tablefiles.add(创建时间的字段);
        tablefiles.add(修改时间的字段);
        strategy.setTableFillList(tablefiles);*/

        //乐观锁
        /*strategy.setVersionFieldName("version");*/
        strategy.setRestControllerStyle(true);
        strategy.setControllerMappingHyphenStyle(true);
        mpg.setStrategy(strategy);
        mpg.execute();

    }

}
